﻿#region LicenseInfo
/*
 * WoW Automation
 * Copyright 2008, 2009
 * Michael Sutton
 * 
 * This file is part of Wow Automation.
 * 
 * Wow Automation is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Wow Automation is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Wow Automation.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Diagnostics;
using Boo.Lang.Interpreter;

using Boo.Lang.Compiler;
using System.Threading;





namespace Automation
{




    public partial class MainApplicationForm : Form
    {
        private readonly KeyPushUtils _KeyUtilities = new KeyPushUtils();
        private readonly BootStrapper _BootStrapper = new BootStrapper();
        private readonly InteractiveInterpreter interpreter = new InteractiveInterpreter();
        private const Keys KeyObject = new Keys();
        private readonly System.Collections.Hashtable commands = new System.Collections.Hashtable();
        private readonly System.Collections.Hashtable CompiledObjects = new System.Collections.Hashtable();

        public MainApplicationForm()
        {
            InitializeComponent();
    
            //Resize windows.   I don't feel like putting in scaling code for the mouse.
            Win32Support.SetPositionSize("World of Warcraft", 0, 0, 1024, 600);
            if (Environment.ProcessorCount >= 2)
            {
                Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)(2);
            }
            _BootStrapper.ZoneChanged += bs_ZoneChanged;
            _BootStrapper.isDeadChanged += bs_isDeadChanged;
            _BootStrapper.InRaidChanged += bs_InRaidChanged;
            _BootStrapper.inQueueChanged += bs_inQueueChanged;
            _BootStrapper.SubZoneChanged += bs_SubZoneChanged;
            _BootStrapper.PositionChanged += bs_PositionChanged;
            _BootStrapper.coordsFacingChanged += bs_coordsFacingChanged;
            interpreter.References.Add(System.Reflection.Assembly.GetExecutingAssembly());
            _KeyUtilities.ScrapeScreen();
            popuateList();
            textBox1.Text = "";
            timer1.Enabled = checkBox1.Checked;
            LoadScripts();

        }


        /// <summary>
        /// Loads script file text, returns it as a string
        /// </summary>
        /// <param name="fileName">File Name to load</param>
        /// <returns></returns>
        private static string LoadScript(string fileName)
        {

            System.IO.FileStream tr = new System.IO.FileStream(fileName, System.IO.FileMode.Open);
            char[] buffer = new char[tr.Length];
            using (System.IO.StreamReader strmReader = new System.IO.StreamReader(tr))
            {
                strmReader.Read(buffer, 0, (int)tr.Length);
            }
            return new string(buffer, 0, buffer.Length);
        }

        private void LoadScripts()
        {
            commands.Clear();
            commands.Add("DeadChanged",LoadScript("BooScripts\\DeadChanged.boo"));
            commands.Add("FacingChanged", LoadScript("BooScripts\\FacingChanged.boo"));
            commands.Add("Idle", LoadScript("BooScripts\\Idle.boo"));
            commands.Add("PositionChanged", LoadScript("BooScripts\\PositionChanged.boo"));
            commands.Add("QueuedChanged", LoadScript("BooScripts\\QueuedChanged.boo"));
            commands.Add("RaidChanged", LoadScript("BooScripts\\RaidChanged.boo"));
            commands.Add("SubChanged", LoadScript("BooScripts\\SubChanged.boo"));
            commands.Add("ZoneChange", LoadScript("BooScripts\\ZoneChange.boo"));
            commands.Add("avStart", LoadScript("BooScripts\\avStart.boo"));
            commands.Add("avDunBaldar", LoadScript("BooScripts\\avDunBaldar.boo"));
            commands.Add("avStormpike", LoadScript("BooScripts\\avStormpike.boo"));
            commands.Add("avWinteraxHold", LoadScript("BooScripts\\avWinteraxHold.boo"));
            commands.Add("avIceBlood", LoadScript("BooScripts\\avIceBlood.boo"));
            commands.Add("avStoneHearth", LoadScript("BooScripts\\avStoneHearth.boo"));
            commands.Add("avFrostwolf", LoadScript("BooScripts\\avFrostwolf.boo"));
            commands.Add("avRelifHut", LoadScript("BooScripts\\avRelifHut.boo"));
            commands.Add("abStart", LoadScript("BooScripts\\abStart.boo"));
            commands.Add("abGyTrollbane", LoadScript("BooScripts\\abGyTrollbane.boo"));
            commands.Add("abGyStables", LoadScript("BooScripts\\abGyStables.boo"));
            commands.Add("abGyGoldMine", LoadScript("BooScripts\\abGyGoldMine.boo"));
            commands.Add("abGyFarm", LoadScript("BooScripts\\abGyFarm.boo"));
            commands.Add("abGyLumberMill", LoadScript("BooScripts\\abGyLumberMill.boo"));
            commands.Add("abGyBlackSmith", LoadScript("BooScripts\\abGyBlackSmith.boo"));
            commands.Add("abGyDefilersDen", LoadScript("BooScripts\\abGyDefilersDen.boo"));
            commands.Add("eosStart", LoadScript("BooScripts\\eosStart.boo"));
            commands.Add("eosMageTower", LoadScript("BooScripts\\eosMageTower.boo"));
            commands.Add("eosDraeneiRuins", LoadScript("BooScripts\\eosDraeneiRuins.boo"));
            commands.Add("eosBloodElfTower", LoadScript("BooScripts\\eosBloodElfTower.boo"));
            commands.Add("eosFelReaverRuins", LoadScript("BooScripts\\eosFelReaverRuins.boo"));
            commands.Add("wsgStart", LoadScript("BooScripts\\wsgStart.boo"));
            commands.Add("wsgGy", LoadScript("BooScripts\\wsgGy.boo"));
        }



        private void popuateList()
        {
            listBox1.SuspendLayout();
            listBox1.Items.Clear();
            listBox1.Items.Add("X:" + CommonVariables.PlayerStatus.X);
            listBox1.Items.Add("Y:" + CommonVariables.PlayerStatus.Y);
            listBox1.Items.Add(string.Format("Facing:{0}", (CommonVariables.PlayerStatus.Facing / 100.0).ToString("N2")));
            listBox1.Items.Add(string.Format("Darnassus:{0}", CommonVariables.PlayerStatus.Darnassus));
            listBox1.Items.Add(string.Format("IronForge:{0}", CommonVariables.PlayerStatus.IronForge));
            listBox1.Items.Add(string.Format("Shatrath:{0}", CommonVariables.PlayerStatus.Shatrath));
            listBox1.Items.Add(string.Format("Stormwind:{0}", CommonVariables.PlayerStatus.Stormwind));
            listBox1.Items.Add(string.Format("SilverMoon:{0}", CommonVariables.PlayerStatus.SilverMoon));
            listBox1.Items.Add(string.Format("AB:{0}", CommonVariables.PlayerStatus.AB));
            listBox1.Items.Add(string.Format("AV:{0}", CommonVariables.PlayerStatus.AV));
            listBox1.Items.Add(string.Format("GotoAV:{0}", CommonVariables.PlayerStatus.GotoAV));
            listBox1.Items.Add(string.Format("EOS:{0}", CommonVariables.PlayerStatus.EOS));
            listBox1.Items.Add(string.Format("WSG:{0}", CommonVariables.PlayerStatus.WSG));
            listBox1.Items.Add(string.Format("Dead:{0}", CommonVariables.PlayerStatus.Dead));
            listBox1.Items.Add(string.Format("inQueue:{0}", CommonVariables.PlayerStatus.inQueue));
            listBox1.Items.Add(string.Format("InRaid:{0}", CommonVariables.PlayerStatus.InRaid));
            listBox1.Items.Add(string.Format("Inside:{0}", CommonVariables.PlayerStatus.Inside));
            listBox1.Items.Add(string.Format("Outside:{0}", CommonVariables.PlayerStatus.Outside));

            listBox1.Items.Add(string.Format("ABgy1:{0}", CommonVariables.PlayerStatus.abGraveYard1));
            listBox1.Items.Add(string.Format("ABgy2:{0}", CommonVariables.PlayerStatus.abGraveYard2));
            listBox1.Items.Add(string.Format("ABgy3:{0}", CommonVariables.PlayerStatus.abGraveYard3));
            listBox1.Items.Add(string.Format("ABgy4:{0}", CommonVariables.PlayerStatus.abGraveYard4));
            listBox1.Items.Add(string.Format("ABgy5:{0}", CommonVariables.PlayerStatus.abGraveYard5));
            listBox1.Items.Add(string.Format("ABgy6:{0}", CommonVariables.PlayerStatus.abGraveYard6));
            listBox1.Items.Add(string.Format("ABgy7:{0}", CommonVariables.PlayerStatus.abGraveYard7));

            listBox1.Items.Add(string.Format("AVgy0:{0}", CommonVariables.PlayerStatus.avGraveYard1));
            listBox1.Items.Add(string.Format("AVgy1:{0}", CommonVariables.PlayerStatus.avGraveYard2));
            listBox1.Items.Add(string.Format("AVgy2:{0}", CommonVariables.PlayerStatus.avGraveYard3));
            listBox1.Items.Add(string.Format("AVgy3:{0}", CommonVariables.PlayerStatus.avGraveYard4));
            listBox1.Items.Add(string.Format("AVgy4:{0}", CommonVariables.PlayerStatus.avGraveYard5));
            listBox1.Items.Add(string.Format("AVgy5:{0}", CommonVariables.PlayerStatus.avGraveYard6));
            listBox1.Items.Add(string.Format("AVgy6:{0}", CommonVariables.PlayerStatus.avGraveYard7));
            listBox1.Items.Add(string.Format("AVgy7:{0}", CommonVariables.PlayerStatus.avGraveYard8));
            

            listBox1.Items.Add(string.Format("EOSgy1:{0}", CommonVariables.PlayerStatus.eosGraveYard1));
            listBox1.Items.Add(string.Format("EOSgy2:{0}", CommonVariables.PlayerStatus.eosGraveYard2));
            listBox1.Items.Add(string.Format("EOSgy3:{0}", CommonVariables.PlayerStatus.eosGraveYard3));
            listBox1.Items.Add(string.Format("EOSgy4:{0}", CommonVariables.PlayerStatus.eosGraveYard4));
            listBox1.Items.Add(string.Format("EOSgy5:{0}", CommonVariables.PlayerStatus.eosGraveYard5));



            listBox1.Items.Add(string.Format("WSGgy1:{0}", CommonVariables.PlayerStatus.wsgGraveYard));

            listBox1.ResumeLayout();

        }
        private void ProcessEvents()
        {
            _KeyUtilities.ScrapeScreen();
            popuateList();
            _BootStrapper.processPass();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            LoadScripts();
            timer1.Interval = 30000;
            popuateList();
            pictureBox1.Image = _BootStrapper.processPass();

            _KeyUtilities.ScrapeScreen();
            Win32Support.SetPositionSize("World of Warcraft", 0, 0, 1024, 600);

            if (CommonVariables.PlayerStatus.X != -1)
            {
                CommonVariables.PlayerStatus.GotoAB = false;
                CommonVariables.PlayerStatus.GotoAV = false;
                CommonVariables.PlayerStatus.GotoWSG = false;
                CommonVariables.PlayerStatus.GotoEOS = false;
                CommonVariables.PlayerStatus.isHorde = false;
                CommonVariables.PlayerStatus.isAlliance = false;

       
                    CommonVariables.PlayerStatus.GotoAB = rbAB.Checked;
        
      
                    CommonVariables.PlayerStatus.GotoAV = rbAV.Checked;
            
      
                    CommonVariables.PlayerStatus.GotoEOS = rbEOS.Checked;
        
   
                    CommonVariables.PlayerStatus.GotoWSG = rbWSG.Checked;
              
     
                    CommonVariables.PlayerStatus.isAlliance = rbAlliance.Checked;
         

                    CommonVariables.PlayerStatus.isHorde = rbHorde.Checked;
             
                interpreter.SetValue("playerStatus", CommonVariables.PlayerStatus);
                interpreter.SetValue("keyFunc", _KeyUtilities);
                interpreter.SetValue("Keys", KeyObject);
                interpreter.ShowWarnings = true;
                ExecuteScript("tbIdle", (string)commands["Idle"]);

            }


            timer1.Enabled = true;
        }


        private void ExecuteScript(string name, string script)
        {
            timer1.Enabled = false;
            timer2.Enabled = false;
            //prep script
            string scriptMod = script.Replace("\0", " ").Trim();
            interpreter.Reset();
            _KeyUtilities.ScrapeScreen();
            CommonVariables.PlayerStatus.GotoAB = false;
            CommonVariables.PlayerStatus.GotoAV = false;
            CommonVariables.PlayerStatus.GotoWSG = false;
            CommonVariables.PlayerStatus.GotoEOS = false;
            CommonVariables.PlayerStatus.isHorde = false;
            CommonVariables.PlayerStatus.isAlliance = false;

    
                CommonVariables.PlayerStatus.GotoAB = rbAB.Checked;    
      
    
                CommonVariables.PlayerStatus.GotoAV = rbAV.Checked ;
    
                CommonVariables.PlayerStatus.GotoEOS = rbEOS.Checked ;
  
                CommonVariables.PlayerStatus.GotoWSG = rbWSG.Checked;
   
                CommonVariables.PlayerStatus.isAlliance = rbAlliance.Checked ;
  
                CommonVariables.PlayerStatus.isHorde = rbHorde.Checked ;
        
            
            

            if (CompiledObjects.Contains(name))
            {
                CompilerContext cc1 = (CompilerContext)CompiledObjects[name];
                if (cc1.GeneratedAssembly != null)
                {
                    interpreter.SetValue("playerStatus", CommonVariables.PlayerStatus);
                    interpreter.SetValue("keyFunc", _KeyUtilities);
                    interpreter.SetValue("Keys", KeyObject);
                    interpreter.ExecuteEntryPoint(cc1.GeneratedAssembly);
                }
                else
                {
                    foreach (CompilerError error in cc1.Errors)
                        Console.WriteLine(error);
                }

            }
            else
            {
                
                interpreter.SetValue("playerStatus", CommonVariables.PlayerStatus);
                interpreter.SetValue("keyFunc", _KeyUtilities);
                interpreter.SetValue("Keys", KeyObject);

                interpreter.ShowWarnings = true;
                CompilerContext cc1 = interpreter.Eval(scriptMod);

                if (!CompiledObjects.Contains(name)) 
                    CompiledObjects.Add(name, cc1);
            }

            timer1.Enabled = true;
            timer2.Enabled = true;

        }

        #region Ab Battleground
        private void abStart()
        {
            LoadScripts();
            ExecuteScript("abStart", (string)commands["abStart"]);
        }
        private void abGyStables()
        {
            ExecuteScript("abGyStables", (string)commands["abGyStables"]);
        }
        private void abGyTrollbane()
        {
            ExecuteScript("abGyTrollbane", (string)commands["abGyTrollbane"]);
        }
        private void abGyGoldMine()
        {

            ExecuteScript("abGyGoldMine", (string)commands["abGyGoldMine"]);

        }
        private void abGyFarm()
        {

            ExecuteScript("abGyFarm", (string)commands["abGyFarm"]);

        }
        private void abGyLumberMill()
        {

            ExecuteScript("abGyLumberMill", (string)commands["abGyLumberMill"]);


        }
        private void abGyBlackSmith()
        {

            ExecuteScript("abGyBlackSmith", (string)commands["abGyBlackSmith"]);

        }
        private void abGyDefilersDen()
        {
            ExecuteScript("abGyDefilersDen", (string)commands["abGyDefilersDen"]);

        }

        #endregion

        #region AV BattleGround
        private void avStart()
        {
            ExecuteScript("avStart", (string)commands["avStart"]);
        }
        private void avDunBaldarPass()
        { avStart(); }
        private void avDunBaldar()
        {

            ExecuteScript("avDunBaldar", (string)commands["avDunBaldar"]);
        }
        private void avStormpike()
        {

            ExecuteScript("avStormpike", (string)commands["avStormpike"]);
        }
        private void avWinteraxHold()
        {

            ExecuteScript("avWinteraxHold", (string)commands["avWinteraxHold"]);
        }
        private void avIceBlood()
        {

            ExecuteScript("avIceBlood", (string)commands["avIceBlood"]);
        }
        private void avStoneHearth()
        {

            ExecuteScript("avStoneHearth", (string)commands["avStoneHearth"]);
        }
        private void avFrostwolf()
        {
            ExecuteScript("avFrostwolf", (string)commands["avFrostwolf"]);
        }
        private void avRelifHut()
        {
            ExecuteScript("avRelifHut", (string)commands["avRelifHut"]);
        }
        #endregion

        #region WSG BattleGround
        private void wsgStart()
        {

            ExecuteScript("wsgStart", (string)commands["wsgStart"]);
        }
        private void wsgGy()
        {
            ExecuteScript("wsgGy", (string)commands["wsgGy"]);
        }
        #endregion

        #region EOS BattleGround
        private void eosStart()
        {

            ExecuteScript("eosStart", (string)commands["eosStart"]);
        }
        private void eosMageTower()
        {
            ExecuteScript("eosMageTower", (string)commands["eosMageTower"]);
        }
        private void eosDraeneiRuins()
        {
            ExecuteScript("eosDraeneiRuins", (string)commands["eosDraeneiRuins"]);
        }
        private void eosBloodElfTower()
        {

            ExecuteScript("eosBloodElfTower", (string)commands["eosBloodElfTower"]);
        }
        private void eosFelReaverRuins()
        {

            ExecuteScript("eosFelReaverRuins", (string)commands["eosFelReaverRuins"]);
        }
        private void eosStartGY()
        { eosStart(); }
        #endregion

        private void button4_Click(object sender, EventArgs e)
        {
            _KeyUtilities.ScrapeScreen();
            pictureBox1.Image = _BootStrapper.processPass();
            textBox1.Text += string.Format("keyFunc.PlayRunToCoords({0}, {1}, playerStatus)\r\n", CommonVariables.PlayerStatus.X, CommonVariables.PlayerStatus.Y);
        }


        void bs_isDeadChanged(object sender, EventBgInfoArgs e)
        {
            //throw new NotImplementedException();
            #region AB bg
            if (e.CurrentBGinfo.AB)
            {
                if (e.CurrentBGinfo.abGraveYard1) //TrollBane Hall
                {
                    abGyTrollbane();
                }
                if (e.CurrentBGinfo.abGraveYard2) //Stables
                {
                    abGyStables();
                }
                if (e.CurrentBGinfo.abGraveYard3) //Gold Mine
                {
                    abGyGoldMine();
                }
                if (e.CurrentBGinfo.abGraveYard4) //Farm
                {
                    abGyFarm();
                }
                if (e.CurrentBGinfo.abGraveYard5) //Lumber Mill
                {
                    abGyLumberMill();
                }
                if (e.CurrentBGinfo.abGraveYard6) //Blacksmith
                {
                    abGyBlackSmith();
                }
                if (e.CurrentBGinfo.abGraveYard7) //DefilersDen
                {
                    abGyDefilersDen();
                }
            }
            #endregion
            #region AV bg
            if (e.CurrentBGinfo.AV)
            {

                if (e.CurrentBGinfo.avGraveYard1) { avDunBaldarPass(); } //Dun Baldar Pass
                if (e.CurrentBGinfo.avGraveYard2) { avStormpike(); } //Stormpike Graveyard
                if (e.CurrentBGinfo.avGraveYard3) { avDunBaldar(); }  //Dun Baldar
                if (e.CurrentBGinfo.avGraveYard4) { avWinteraxHold(); }  //Winterax Hold
                if (e.CurrentBGinfo.avGraveYard5) { avIceBlood(); }  //Iceblood Graveyard
                if (e.CurrentBGinfo.avGraveYard6) { avStoneHearth(); }  //Stonehearth Graveyard
                if (e.CurrentBGinfo.avGraveYard7) { avFrostwolf(); }  //Frostwolf Graveyard
                if (e.CurrentBGinfo.avGraveYard8) { avRelifHut(); }  //Frostwolf Relif Hut

            }
            #endregion
            #region WSG bg
            if (e.CurrentBGinfo.WSG)
            {
                if (e.CurrentBGinfo.wsgGraveYard)
                {
                    wsgGy();
                }
            }
            #endregion
            #region EOS bg
            if (e.CurrentBGinfo.EOS)
            {
                if (e.CurrentBGinfo.eosGraveYard1) { eosMageTower(); }
                if (e.CurrentBGinfo.eosGraveYard2) { eosDraeneiRuins(); }
                if (e.CurrentBGinfo.eosGraveYard3) { eosBloodElfTower(); }
                if (e.CurrentBGinfo.eosGraveYard4) { eosFelReaverRuins(); }
                if (e.CurrentBGinfo.eosGraveYard5) { eosStartGY(); }
            }
            #endregion
        }
        void bs_ZoneChanged(object sender, EventBgInfoArgs e)
        {
            //KeyPushUtils kpu = new KeyPushUtils();
            //CommonVariables.BGinfo bgi = e.CurrentBGinfo;
            popuateList();
            #region AB bg
            if (e.CurrentBGinfo.AB)
            {
                abStart();
            }
            #endregion
            #region AV bg
            if (e.CurrentBGinfo.AV)
            {
                avStart();
            }
            #endregion
            #region WSG bg
            if (e.CurrentBGinfo.WSG)
            {
                wsgStart();
            }
            #endregion
            #region EOS bg
            if (e.CurrentBGinfo.EOS)
            {
                eosStart();
            }
            #endregion
            #region Darnasis BG wait in queue
            #endregion
            #region Stormwind Bg wait in queue
            #endregion
            #region Shattrath BG wait in queue
            #endregion
            #region Ironforg BG wait in queue
            #endregion

        }

        void bs_coordsFacingChanged(object sender, EventBgInfoArgs e)
        {
            //throw new NotImplementedException();
        }

        void bs_InRaidChanged(object sender, EventBgInfoArgs e)
        {
            //throw new NotImplementedException();
        }

        void bs_PositionChanged(object sender, EventBgInfoArgs e)
        {
            //  throw new NotImplementedException();
        }

        void bs_SubZoneChanged(object sender, EventBgInfoArgs e)
        {
            // throw new NotImplementedException();
        }

        void bs_inQueueChanged(object sender, EventBgInfoArgs e)
        {
            //  throw new NotImplementedException();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked)
            {
                timer1.Enabled = true;
                timer2.Enabled = true;
                timer1.Interval = 2000;
                CommonVariables.PlayerStatus.Quit = false;
               

            }
            else
            {
                timer2.Enabled = false;
                timer1.Enabled = false;
                CommonVariables.PlayerStatus.Quit = true;
       

            }

        }

        private void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            timer2.Enabled = false;
            timer2.Interval = 1000;
           // ExecuteScript("avStart", (string)commands["avStart"]);
            _KeyUtilities.ScrapeScreen();
            //Double dd = _KeyUtilities.DistanceToPoint(CommonVariables.PlayerStatus.X + 100, CommonVariables.PlayerStatus.Y + 100);
            popuateList();
            pictureBox1.Image = _BootStrapper.processPass();


            //timer2.Enabled = false;
            ProcessEvents();
            timer2.Enabled = true;
        }

        Thread MonitorThread;
        private readonly KeyMonitorThread kmt = new KeyMonitorThread();
        private void Form1_Load(object sender, EventArgs e)
        {
            timeAdjustment();
            //start monitorThread
            kmt.AcquireKeyboard(this);
            ThreadStart job = kmt.Run;
            MonitorThread = new Thread(job);
            MonitorThread.Start();
             


        }
        public void closethisthing()
        {
            CommonVariables.PlayerStatus.Quit = true;
            checkBox1.Checked = false;
            timer2.Enabled = false;
            timer1.Enabled = false;
            try
            {
                
            }
            catch (Exception e )
            {
                Debug.WriteLine(e.Message);
            }
            Application.DoEvents();
            Application.DoEvents();
            
        }


        public Delegate myDelegate()
        {
            //this.Close()
            MethodInvoker dd = closethisthing;
            Invoke(dd);
            return null;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            MonitorThread.Abort();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {

        }
        private static void timeAdjustment()
        {
            //the purpose of this is to file out how long on this system it takes for 500 milliseconds to really pass
            long dtControl = DateTime.Now.Ticks;
            Thread.Sleep(250);
            long dtVariable = DateTime.Now.Ticks;

            CommonVariables.oneMilSecond = 250.000f / ( (dtVariable - dtControl)  / 10000.0f);
        
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

        }


        
        void RbAVCheckedChanged(object sender, EventArgs e)
        {
        	
        }
    }
}
